package org.dandsoft.blackbox.laboratory.samples.lighter;

import org.dandsoft.blackbox.snn.Environment;
import org.dandsoft.blackbox.snn.ObjectId;
import org.dandsoft.blackbox.snn.Value;
import org.dandsoft.blackbox.snn.Container;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 24.03.2009 18:15:21
 */
public class Body {

    private Environment environment;
    private Container container;
    private Lighter lighter;
    private ObjectId topNoSun;
    private ObjectId topSunThere;
    private ObjectId topSun;
    private ObjectId rightNoSun;
    private ObjectId rightSunThere;
    private ObjectId rightSun;
    private ObjectId bottomNoSun;
    private ObjectId bottomSunThere;
    private ObjectId bottomSun;
    private ObjectId leftNoSun;
    private ObjectId leftSunThere;
    private ObjectId leftSun;
    private ObjectId lowBattary;

    private ObjectId moveUp;
    private ObjectId moveRight;
    private ObjectId moveDown;
    private ObjectId moveLeft;


    public Body(Environment environment, Container container) {
        this.environment = environment;
        this.container = container;

        this.topNoSun = environment.createInput();
        this.topSun = environment.createInput();
        this.topSunThere = environment.createInput();

        this.rightNoSun = environment.createInput();
        this.rightSun = environment.createInput();
        this.rightSunThere = environment.createInput();

        this.bottomNoSun = environment.createInput();
        this.bottomSun = environment.createInput();
        this.bottomSunThere = environment.createInput();

        this.leftNoSun = environment.createInput();
        this.leftSun = environment.createInput();
        this.leftSunThere = environment.createInput();

        this.lowBattary = environment.createInput();


    }

    public void alive() {
        sensors();

        //container.alive(environment);
        environment.alive();
        environment.printTrace();
        environment.study();
    }


    private void sensors() {
        if (LightSensor.SUN_THERE == lighter.getTop().getState()) {
            environment.put(topSunThere, Value.ACTIVE);
            //System.out.print(topSunThere.getValue() + ",");
        } else if (LightSensor.SUN == lighter.getTop().getState()) {
            environment.put(topSun, Value.ACTIVE);
            //System.out.print(topSun.getValue() + ",");
        }

        if (LightSensor.SUN_THERE == lighter.getRight().getState()) {
            environment.put(rightSunThere, Value.ACTIVE);
            ///System.out.print(rightSunThere.getValue() + ",");
        } else if (LightSensor.SUN == lighter.getRight().getState()) {
            environment.put(rightSun, Value.ACTIVE);
            //System.out.print(rightSun.getValue() + ",");
        }

        if (LightSensor.SUN_THERE == lighter.getBottom().getState()) {
            environment.put(bottomSunThere, Value.ACTIVE);
            //System.out.print(bottomSunThere.getValue() + ",");
        } else if (LightSensor.SUN == lighter.getBottom().getState()) {
            environment.put(bottomSun, Value.ACTIVE);
            //System.out.print(bottomSun.getValue() + ",");
        }

        if (LightSensor.SUN_THERE == lighter.getLeft().getState()) {
            environment.put(leftSunThere, Value.ACTIVE);
            //System.out.print(leftSunThere.getValue() + ",");
        } else if (LightSensor.SUN == lighter.getLeft().getState()) {
            environment.put(leftSun, Value.ACTIVE);
           // System.out.print(leftSun.getValue() + ",");
        }
       // System.out.println();
    }

    public Lighter getLighter() {
        return lighter;
    }

    public void setLighter(Lighter lighter) {
        this.lighter = lighter;
    }
}
